package language;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class LArrayBuilder extends LFunction<LType, LArrayBuilder> {

    public static final LArrayBuilder EMPTY_ARRAY_BUILDER = new LArrayBuilder();
    
    private final List<LType> list;

    private LArrayBuilder() {
        list = new ArrayList();
    }

    private LArrayBuilder(List list) {
        this.list = list;
    }

    @Override
    public LArrayBuilder accept(LType t, Map<Character, LType> vars) {
        List newList = new ArrayList(list);
        newList.add(t);
        return new LArrayBuilder(newList);
    }

    @Override
    public LArray<LType> asArray() {
        return LArray.of(new ArrayList(list));
    }
}
